<?php

class Application_Model_DbTable_ShopType extends Zend_Db_Table_Abstract
{

    protected $_name = 'Shop_type';

    public function assign($shop_id,$categories){
        foreach($categories as $category){
            $data = array(
                "shop_id" => $shop_id,
                "category_id" => $category
            );
            $this->insert($data);
        }
    }
    
    public function unassign($shop_id){
        $this->delete("shop_id = ".(int)$shop_id);
    }

    public function countCategory(){
        $query = $this->select();
        $query->from(array("st"=>"Shop_type"),array("total"=>"count(st.category_id)"));
        $query->joinInner(array("c"=>"Category"), "st.category_id = c.category_id", array("name"));
        $query->setIntegrityCheck(false);
        $query->group("name");
        return $this->fetchAll($query);
    }
}

